package com.ruoyi.demo.controller.sendEvent;

import com.baomidou.mybatisplus.annotation.OrderBy;
import com.ruoyi.demo.domain.TestDemo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * <简述>
 * <详细描述>
 *
 * @author syf
 * @date 2024年05月15日 10:09
 */
@Slf4j
//1-必须交给spring管理
@Component
public class EventListen {
//    @EventListener
//    @Order(1)
//    public  void listen1(TestDemo demo){
//        log.info("demo1111--------->{}", demo);
//    }
//
//    @Order(2)
//    @EventListener
//    @Async
//    public  void listen2(TestDemo demo){
//        log.info("demo2222222--------->{}", demo);
//    }

    @TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
    public  void listen3(TestDemo demo){
        log.info("事务提交成功--------->{}", demo);
    }

    @TransactionalEventListener(phase = TransactionPhase.AFTER_ROLLBACK)
    public  void listen4(TestDemo demo){
        log.info("触发事务回滚--------->{}", demo);
    }

}
